package com.jic.member.impl;

import java.lang.Long;
import java.util.List;

import com.jic.member.entity.MememberGrowthOrderMoney;
import com.jic.member.mapper.MememberGrowthOrderMoneyMapper;
import com.jic.member.service.MememberGrowthOrderMoneyService;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 会员等级管理-成长值规则-N次下单-充值赠送表
 *
 * @author :
 * @version : v1.0.0
 * @email :
 * @since : 2020-04-10 07:43:17
 */
@Service
public class MememberGrowthOrderMoneyServiceImpl implements MememberGrowthOrderMoneyService {

    @Autowired
    private MememberGrowthOrderMoneyMapper mememberGrowthOrderMoneyMapper;

    @Override
    public long insert(MememberGrowthOrderMoney mememberGrowthOrderMoney) {
        long flag = mememberGrowthOrderMoneyMapper.insert(mememberGrowthOrderMoney);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return mememberGrowthOrderMoneyMapper.delete(id);
    }

    @Override
    public long update(MememberGrowthOrderMoney mememberGrowthOrderMoney) {
        return mememberGrowthOrderMoneyMapper.update(mememberGrowthOrderMoney);
    }

    @Override
    public MememberGrowthOrderMoney queryByPrimaryKey(Long id) {
        return mememberGrowthOrderMoneyMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<MememberGrowthOrderMoney> query(MememberGrowthOrderMoney mememberGrowthOrderMoney) {
        return mememberGrowthOrderMoneyMapper.query(mememberGrowthOrderMoney);
    }

    @Override
    public PageResult<MememberGrowthOrderMoney> queryPage(MememberGrowthOrderMoney mememberGrowthOrderMoney, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<MememberGrowthOrderMoney> list = mememberGrowthOrderMoneyMapper.queryPage(startIndex, pageQuery.getLimit(), mememberGrowthOrderMoney);
        long count = mememberGrowthOrderMoneyMapper.queryPageCount(mememberGrowthOrderMoney);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    //根据中间表id删除原有记录
    public long deleteByOrderId(Long id) {
        return mememberGrowthOrderMoneyMapper.deleteByOrderId(id);
    }

    @Override
    //根据成长值规则表主id查询成长值
    public MememberGrowthOrderMoney getGiveGrowthValById(Long id) {

        MememberGrowthOrderMoney mememberGrowthOrderMoney = new MememberGrowthOrderMoney();
        Long val = mememberGrowthOrderMoneyMapper.getGiveGrowthValById(id);
         mememberGrowthOrderMoney.setGiveGrowthVal(val);
        return mememberGrowthOrderMoney;
    }

    @Override
    public Long getSumGiveGrowthValById(Long id) {
        Long val = mememberGrowthOrderMoneyMapper.getSumGiveGrowthValById(id);

        return val;

    }
}